fix: decouple stream listeners from stream entry lifecycle#183
Merged
op7418 merged 1 commit intoop7418:mainfrom Mar 7, 2026
Merged
fix: decouple stream listeners from stream entry lifecycle#183op7418 merged 1 commit intoop7418:mainfrom
op7418 merged 1 commit intoop7418:mainfrom
Conversation
Stream event listeners were stored inside ActiveStream objects, which get garbage collected 5 minutes after completion. When a new stream started after GC (especially during Fast Refresh/HMR), startStream created a fresh entry with an empty listener set, causing the UI to freeze with no updates delivered. Move listeners to a separate globalThis-persisted registry (__streamSessionListeners__) that survives stream entry GC. The subscribe and emit functions now read/write from this independent map instead of stream.listeners. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stream event listeners were stored inside
ActiveStreamobjects, which get garbage collected 5 minutes after completion. When a new stream started after GC — especially during Fast Refresh/HMR in development —startStreamcreated a freshActiveStreamentry with an empty listener set. This caused the UI to freeze with no updates delivered, since the component's subscription was attached to the old (now-deleted) entry.Root cause
stream.listenerslived on theActiveStreamobject itself. The GC lifecycle (scheduleGC→delete streams[sessionId]) destroyed the listener set along with the stream. Any component that subscribed before GC but received events after GC would silently lose its subscription.Fix
Moved listeners to a separate
globalThis-persisted registry (__streamSessionListeners__) that survives stream entry GC. Thesubscribeandemitfunctions now read/write from this independent map instead ofstream.listeners.This means:
Files changed
src/lib/stream-session-manager.ts— extract listener registry fromActiveStreamtoglobalThis.__streamSessionListeners__Test plan
npm run testpasses (typecheck + unit tests)🤖 Generated with Claude Code